package com.hikvision.cms.common.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;


public class EncrypDES {
    public static String getMD5(String str) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");

            md.update(str.getBytes());


            String md5 = (new BigInteger(1, md.digest())).toString(16);

            return fillMD5(md5);
        } catch (Exception e) {
            throw new RuntimeException("MD5加密错误:" + e.getMessage(), e);
        }
    }

    public static String fillMD5(String md5) {
        return (md5.length() == 32) ? md5 : fillMD5("0" + md5);
    }

    public static String getDateTimeAsString(LocalDateTime localDateTime, String format) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
        return localDateTime.format(formatter);
    }


    public static Long convertTimeToLong(String timestr) {
        DateTimeFormatter ftf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime parse = LocalDateTime.parse(timestr, ftf);
        return Long.valueOf(LocalDateTime.from(parse).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() / 1000L);
    }


}


